package com.kld.system.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.kld.common.utils.StringUtils;
import com.kld.common.core.page.TableDataInfo;
import com.kld.common.core.domain.PageQuery;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.kld.system.domain.SysSyncTime;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import com.kld.system.domain.vo.SysUserMdmVo;
import com.kld.system.domain.SysUserMdm;
import com.kld.system.mapper.SysUserMdmMapper;
import com.kld.system.service.ISysUserMdmService;

import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Collection;

/**
 * 用户信息Service业务层处理
 *
 * @author kld
 * @date 2022-06-16
 */
@RequiredArgsConstructor
@Service
public class SysUserMdmServiceImpl implements ISysUserMdmService {

    private final SysUserMdmMapper baseMapper;


    /**
     * 查询用户信息列表
     *
     *
     * @return 用户信息
     */
    @Override
    @DS("slave")
    public List<SysUserMdmVo> selectUserMdmList(SysSyncTime syncTime) {
        Date time = null;
         if(syncTime != null ){
             time =  syncTime.getSyncTime();
         }
        SysUserMdm sysUserMdm = new SysUserMdm();
        sysUserMdm.setUpdateTime(time);
        return baseMapper.selectUserMdmList(sysUserMdm);
    }

    private LambdaQueryWrapper<SysUserMdm> buildQueryWrapper(SysUserMdm bo) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<SysUserMdm> lqw = Wrappers.lambdaQuery();
        lqw.eq(StringUtils.isNotBlank(bo.getUserId()), SysUserMdm::getUserId, bo.getUserId());
        lqw.eq(bo.getTenantId() != null, SysUserMdm::getTenantId, bo.getTenantId());
        lqw.eq(bo.getGroupId() != null, SysUserMdm::getGroupId, bo.getGroupId());
        lqw.like(StringUtils.isNotBlank(bo.getLoginName()), SysUserMdm::getLoginName, bo.getLoginName());
        lqw.like(StringUtils.isNotBlank(bo.getDisplayName()), SysUserMdm::getDisplayName, bo.getDisplayName());
        lqw.eq(StringUtils.isNotBlank(bo.getPassword()), SysUserMdm::getPassword, bo.getPassword());
        lqw.eq(bo.getDomainId() != null, SysUserMdm::getDomainId, bo.getDomainId());
        lqw.eq(StringUtils.isNotBlank(bo.getEmail()), SysUserMdm::getEmail, bo.getEmail());
        lqw.eq(StringUtils.isNotBlank(bo.getMobile()), SysUserMdm::getMobile, bo.getMobile());
        lqw.eq(bo.getUserType() != null, SysUserMdm::getUserType, bo.getUserType());
        lqw.eq(bo.getForbidden() != null, SysUserMdm::getForbidden, bo.getForbidden());
        lqw.eq(bo.getChangeInitPassword() != null, SysUserMdm::getChangeInitPassword, bo.getChangeInitPassword());
        lqw.eq(bo.getStatus() != null, SysUserMdm::getStatus, bo.getStatus());
        lqw.eq(StringUtils.isNotBlank(bo.getEmployeeNumber()), SysUserMdm::getEmployeeNumber, bo.getEmployeeNumber());
        lqw.eq(StringUtils.isNotBlank(bo.getEmployeeCreateBy()), SysUserMdm::getEmployeeCreateBy, bo.getEmployeeCreateBy());
        lqw.like(StringUtils.isNotBlank(bo.getEmployeeOrgName()), SysUserMdm::getEmployeeOrgName, bo.getEmployeeOrgName());
        lqw.eq(bo.getSort() != null, SysUserMdm::getSort, bo.getSort());
        lqw.eq(bo.getDel() != null, SysUserMdm::getDel, bo.getDel());
        lqw.eq(bo.getCreator() != null, SysUserMdm::getCreator, bo.getCreator());
        lqw.eq(bo.getUpdator() != null, SysUserMdm::getUpdator, bo.getUpdator());
        lqw.eq(StringUtils.isNotBlank(bo.getOuterId()), SysUserMdm::getOuterId, bo.getOuterId());
        lqw.eq(StringUtils.isNotBlank(bo.getExtend1()), SysUserMdm::getExtend1, bo.getExtend1());
        lqw.eq(StringUtils.isNotBlank(bo.getExtend2()), SysUserMdm::getExtend2, bo.getExtend2());
        lqw.eq(StringUtils.isNotBlank(bo.getExtend3()), SysUserMdm::getExtend3, bo.getExtend3());
        lqw.eq(StringUtils.isNotBlank(bo.getExtend4()), SysUserMdm::getExtend4, bo.getExtend4());
        lqw.eq(StringUtils.isNotBlank(bo.getExtend5()), SysUserMdm::getExtend5, bo.getExtend5());
        lqw.eq(bo.getExtend6() != null, SysUserMdm::getExtend6, bo.getExtend6());
        lqw.eq(bo.getExtend7() != null, SysUserMdm::getExtend7, bo.getExtend7());
        lqw.eq(bo.getExtend8() != null, SysUserMdm::getExtend8, bo.getExtend8());
        return lqw;
    }

}
